/************************************************************
 * Copyright (C), 2020-2030, ripnano. Co., Ltd.
 * FileName:        form_login.h
 * Author:			Dan Yin
 * Date:            2024-01-03
 * Description:		system login class
 * Version:			1.0.0.0
 **********************************************************/

#ifndef FORM_LOGIN_H
#define FORM_LOGIN_H

// add necessary includes here
#include "ui/defines/global.h"

class QLineEditPwd;

namespace Ui {
class FormLogin;
}

class FormLogin : public QWidget
{
    Q_OBJECT

public:
    // Get an instance of "FormLogin" class, if exist, return it
    static FormLogin* getInstance(QWidget *pParent = nullptr);

signals:
    // The signal that refresh UI info
    void signalRefreshUI();

    // The signal that refresh login mode on the status bar
    void signalRefreshLoginMode(int nLoginMode);

    // Tell the main window that login is complete
    void signalFinishLogin();

private slots:
    // Verify the user name and password to log in to the main screen
    void on_pushButton_Login_clicked();

    // Refresh the password after switch the user
    void on_comboBox_User_currentTextChanged(const QString &arg1);

    // Association remembers password and automatic login
    void on_checkBox_RememberMe_stateChanged(int arg1);

    // Setting automatic login
    void on_checkBox_AutoLogin_stateChanged(int arg1);

    // The slot that refresh UI info
    void slotRefreshUI();

    // Auto login timeout
    void slotAutoLoginTimeout();

protected:
    // Triggers an event before it is switch language
    void changeEvent(QEvent *event);

private:
    // The default constructor
    explicit FormLogin(QWidget *parent = nullptr);

    private:
    // The default destructor
    ~FormLogin();

    // After constructing object, initialize the object
    void _initialze();

    // Init the window style
    void _initUi();

    // Fill the list of users into the combobox
    void _loadUserList();

    // Load login option info
    void _loadLoginOption(QString sUserName="");

    // Save login option info
    void _saveLoginOption();

private:
    Ui::FormLogin *ui;

    QTimer              *m_pTimerLogin = nullptr;
    QLineEditPwd        *m_pLineEditPwd = nullptr;
};

#endif // FORM_LOGIN_H
